// commpents/notfullGroupTime/notfullGroupTime.js
let app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    "endTime": {
      type: String
    },
    "beginTime":{
      type: String,
      value: ""
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },
  observers: {
		// 监听num1和num2的变化 动态改变sum的值
		// 记住num1和num2 data已经更新 下面不需要更新！否则会死循环！
		'beginTime'(begintime) {
      if(begintime){
        // console.log("?",JSON.parse(begintime));
        this.countDown(JSON.parse(begintime),this.properties.endTime)
      }
      // this.countDown(beginTime,this.properties.endTime)
		}
	},
  /**
   * 组件的方法列表
   */
  methods: {
    // 倒计时
    countDown:function(beginTime,endTime){
      var that=this;
      var nowTime = new Date(beginTime).getTime(),
          endTime = new Date(endTime).getTime();//现在时间（时间戳）
      var time = (endTime-nowTime)/1000;//距离结束的毫秒数
      // 获取天、时、分、秒
      let day = parseInt(time / (60 * 60 * 24));
      let hou = parseInt(time % (60 * 60 * 24) / 3600);
      let min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
      let sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);
      day = that.timeFormin(day),
      hou = that.timeFormin(hou),
      min = that.timeFormin(min),
      sec = that.timeFormin(sec)
      that.setData({
        day: that.timeFormat(day),
        hou: that.timeFormat(hou) + that.timeFormat(day)*24,
        min: that.timeFormat(min),
        sec: that.timeFormat(sec)
      })
      // console.log(day + "," + hou + "," + min + "," + sec)
    },
    //小于10的格式化函数（2变成02）
    timeFormat: function(param) {
      // return param < 10 ? '0' + param : param;
      return param;
    },
    //小于0的格式化函数（不会出现负数）
    timeFormin: function(param) {
      return param < 0 ? 0: param;
    },
  },

  lifetimes: {
    attached: function() {
      // 在组件实例进入页面节点树时执行

    },
    detached: function() {
      // 在组件实例被从页面节点树移除时执行
    },
  },
})
